package com.lcj;

import com.geccocrawler.gecco.GeccoEngine;
import com.geccocrawler.gecco.request.HttpPostRequest;
import com.geccocrawler.gecco.spring.SpringGeccoEngine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 先构造ajax登录页面，然后pipeline进入主页进行抓取，能保持登录状态
 */
@SpringBootApplication
@Configuration
public class LoginApplication {
    private static String userName = "15874991816";
    private static String password = "cx821202";
    private static String zptLoginURL = "https://www.zptong.com/plus/ajax_user.php";

    @Bean
    public SpringGeccoEngine initGecco() {
        return new SpringGeccoEngine() {
            @Override
            public void init() {
                HttpPostRequest httppost = new HttpPostRequest(zptLoginURL);

                httppost.addField("username",userName);
                httppost.addField("password",password);
                httppost.addField("expire","7");
                httppost.addField("url","");
                httppost.addField("postcaptcha","");
                httppost.addField("time",String.valueOf(System.currentTimeMillis()));
                httppost.addField("act","do_login");
                GeccoEngine.create()
                        .pipelineFactory(springPipelineFactory)
                        .classpath("com.lcj")
                        .start(httppost)
                        .interval(1000)
                        .debug(false)
                        .start();
            }
        };
    }
    public static void main(String[] args) throws Exception {
        SpringApplication.run(LoginApplication.class, args);
    }
}
